package edu.guet.server.service;

import java.util.List;

import edu.guet.server.utils.SortABC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.guet.server.mapper.QSSelectMapper;
import edu.guet.server.model.QSSelect;
import edu.guet.server.utils.ResultAPI;

@Service
public class QSSelectService {
    @Autowired
    QSSelectMapper qsSelectMapper;

    public ResultAPI setQSSelect(QSSelect qsSelect){
        qsSelect.setRight_ans(SortABC.sortabc(qsSelect.getRight_ans()));
        qsSelectMapper.setQSSelect(qsSelect);
        return ResultAPI.success(qsSelect, "设置选择题成功");
    }

    public ResultAPI getQSSelect(Integer tech_id){
        List<QSSelect> list = qsSelectMapper.getQSSelect(tech_id);
        return ResultAPI.success(list, "获取成功");
    }

    public ResultAPI deleteQSSelect(int qs_id){
        boolean result = qsSelectMapper.deleteQSSelect(qs_id);

        if (result) {
            return ResultAPI.success("删除成功");
        } else {
            return ResultAPI.error("删除失败");
        }
    }

    public ResultAPI resetQSSelect(QSSelect qsSelect){
        boolean result = qsSelectMapper.resetQSSelect(qsSelect);

        if (result) {
            return ResultAPI.success("设置成功");
        } else {
            return ResultAPI.error("设置失败");
        }
    }
}
